﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AMS.Core.Importors;
using AMS.History.Importor;
using VitCode.BaseDataPageCreator.Setting;
using VitCode.Castle.Entities;

namespace AMS.Web.BaseData.Helper
{
    public class ImportorFactory
    {
        /// <summary>
        /// 私有构造函数
        /// </summary>
        private ImportorFactory()
        {
        }

        /// <summary>
        /// 实例化具体的导入对象(根据有文件名创建对象)
        /// </summary>
        /// <param name="filePath">要导入的EXCEL文件路径</param>
        /// <param name="sheetName">要导入数据的工作表名称</param>
        /// <param name="userGroupName">实物管理部门名称</param>
        /// <param name="currentUser">当前登录用户</param>
        /// <param name="languageKey">语言版本关键字</param>
        /// <returns>导入对象</returns>
        public static AbstractImportor ImportorInstance(string filePath, string sheetName, string userGroupName, User currentUser)
        {

            string strFileName = filePath;
            int index = strFileName.LastIndexOf("\\");
            strFileName = strFileName.Substring(index + 1, strFileName.Length - index - 1);
            strFileName = strFileName.ToUpper();
            if (strFileName.IndexOf("地点信息导入") >= 0)
            {
                return new SiteImportor(filePath, sheetName, currentUser,"House");
            }
            else if (strFileName.IndexOf("仓库信息导入") >= 0)
            {
                return new SiteImportor(filePath, sheetName, currentUser, "Warehouse");
            }
            else if (strFileName.IndexOf("主资产导入") >= 0)
            {
                return new AssetInfoImportor(filePath, sheetName, currentUser, "MainAsset");
            }
            else if (strFileName.IndexOf("低值易耗品导入") >= 0)
            {
                return new AssetInfoImportor(filePath, sheetName, currentUser, "LowValueAsset");
            }
            else if (strFileName.IndexOf("备品备件导入") >= 0)
            {
                return new AssetInfoImportor(filePath, sheetName, currentUser, "StorageAsset");
            }
            else if (strFileName.IndexOf("依附性资产导入") >= 0)
            {
                return new AssetInfoImportor(filePath, sheetName, currentUser, "SubAsset");
            }
            else if (strFileName.IndexOf("部门信息导入") >= 0)
            {
                return new DepartmentImportor(filePath, sheetName, currentUser);
            }
            else if (strFileName.IndexOf("用户信息导入") >= 0)
            {
                return new UserImportor(filePath, sheetName, currentUser);
            }
            else if (strFileName.IndexOf("类别编码信息导入") >= 0)
            {
                return new AssetTypeImportor(filePath, sheetName, currentUser);
            }
            else
              throw new ArgumentOutOfRangeException("导入Excel文件的文件名称", "未知的类型，请检查导入的名称是否符合要求");
        }
    }
}
